package com.spatio.serving.basic.service.template.common.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonSerUtil {

    private static final ObjectMapper objectMapper = new ObjectMapper();

    // 将对象序列化为 JSON 字符串
    public static String serialize(Object obj) throws JsonProcessingException {
        return objectMapper.writeValueAsString(obj);
    }

    // 将 JSON 字符串反序列化为对象
    public static <T> T deserialize(String json, Class<T> clazz) throws JsonProcessingException {
        return objectMapper.readValue(json, clazz);
    }
}